package com.wanxi.service.Impl;

import com.wanxi.dao.Impl.MajorDaoImpl;
import com.wanxi.dao.MajorDao;
import com.wanxi.dto.ResultDto;
import com.wanxi.model.MajorModel;
import com.wanxi.service.MajorService;

/**
 * @author Li
 * @Date 2023/5/15 16:06
 */
public class MajorServiceImpl implements MajorService {
    private MajorDao majorDao = new MajorDaoImpl();
    @Override
    public ResultDto add(MajorModel majorModel) {
        boolean same = majorDao.findSameName(majorModel);
        if (same){
            return ResultDto.builder()
                    .code(0)
                    .msg("服务名已存在")
                    .build();
        }
        return ResultDto.builder()
                .code(0)
                .msg("新增成功")
                .count(majorDao.add(majorModel))
                .build();
    }

    @Override
    public ResultDto update(MajorModel majorModel) {

        return ResultDto.builder()
                .code(0)
                .msg("修改成功")
                .count(majorDao.update(majorModel))
                .build();
    }

    @Override
    public ResultDto delete(MajorModel majorModel) {

        return ResultDto.builder()
                .code(0)
                .msg("删除成功")
                .count(majorDao.delete(majorModel))
                .build();
    }

    @Override
    public ResultDto findAll(MajorModel majorModel) {

        return ResultDto.builder()
                .code(0)
                .msg("查询成功")
                .count(majorDao.count(majorModel))
                .data(majorDao.findAll(majorModel))
                .build();
    }

    @Override
    public ResultDto findById(MajorModel majorModel) {

        return ResultDto.builder()
                .code(0)
                .msg("查询成功")
                .data(majorDao.findById(majorModel))
                .build();
    }

    @Override
    public Integer totalCount() {
        return majorDao.totalCount();
    }
}
